package com.hyperion.blog.controller;

import com.hyperion.blog.common.aop.LogAnnotation;
import com.hyperion.blog.service.SSOService;
import com.hyperion.blog.vo.ErrorCode;
import com.hyperion.blog.vo.params.LoginParam;
import com.hyperion.blog.vo.result.Result;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author Hyperion
 */
@RestController
@RequestMapping("/register")
public class RegisterController {

    @Resource
    private SSOService SSOService;

    @PostMapping
    @LogAnnotation(clazz = "RegisterController", method = "register")
    public Result register(@RequestBody LoginParam loginParam) {
        String token = SSOService.register(loginParam);
        if (token == null) {
            return Result.fail(ErrorCode.PARAMS_ERROR);
        }
        return Result.success(token);
    }
}
